﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Web.UI.WebControls;
using System.Data;

namespace DFT.Infos
{
    public class UserInfo
    {
        public Int64 UserId{ get;set;}
        public String FullName { get; set; }
        public String Email { get; set; }
        public DateTime RegistrationDt { get; set; }
        public DateTime Lastlogin { get; set; }
        
        public UserInfo()
        {
        }

        public UserInfo(Int64 userId, String fullName, String email, DateTime registrationDt, DateTime lastlogin)
        {
            this.UserId = userId;
            this.FullName = fullName;
            this.Email = email;
            this.RegistrationDt = registrationDt;
            this.Lastlogin = lastlogin;
        }
    }

    public class Helper
    {
        public static TreeNode BuildTree(DataTable profilesTable, Int64 rootId)
        {
            TreeNode profileNode = new TreeNode();
            DataRow rootProfile;
            String hasChild = "n";
            if (rootId == -1)
            {
                rootProfile = profilesTable.Select("parentProfId Is NULL")[0];
            }
            else
            {
                rootProfile = profilesTable.Select("profId =" + rootId.ToString())[0];
            }
            foreach (DataRow childProfile in profilesTable.Select("parentProfId =" + rootProfile["profId"].ToString()))
            {
                hasChild = "y";
                profileNode.ChildNodes.Add(BuildTree(profilesTable, Int64.Parse(childProfile["profId"].ToString())));
            }
            profileNode.Value = rootProfile["profId"].ToString();
            profileNode.Text = "<a herf='#' id='" + rootProfile["profId"].ToString() + "_" + rootProfile["parentProfId"].ToString() + "_" + rootProfile["gender"].ToString() + "_" + hasChild + "' class='pn pn-" + rootProfile["gender"].ToString() + " text ui-widget-content ui-corner-all' onclick=ProfileForm('Show','" + rootProfile["profId"].ToString() + "','" + rootProfile["parentProfId"].ToString() + "','');><img width='30px' height='30px' src='AJAX/GetImage.aspx?profId=" + rootProfile["profId"].ToString() + "&g=" + rootProfile["gender"].ToString() + "'/>" + rootProfile["firstName"].ToString() + " " + rootProfile["lastName"].ToString() + "</a>";
            profileNode.NavigateUrl = "javascript:";
            return profileNode;
        }

    }

}
